<?php
/** Copyright 2014 TinPhp Systems, Inc.
 * @author zhangxilian 2013-8-20
 * @package TinPhp
 */
if (!defined('IN_TINPHP')) {
	exit ('Access Denied');
}
require_once (TIN_APP_PATH . 'include/TinPHP/DBFactory.php');
/** 虚拟的Logic基类,/app/logic/目录下的类必须继承该类 */
abstract class TinBaseLogic {    
	protected $db_type = TIN_DB_TYPE;
    /** 日志类名 */
    protected $logger;
	private $dbConn;    
	/** 初始化基类，创建数据库链接对象 */
	function __construct() {
		//echo $this->db_type;
		$this->dbConn = DBFactory::getDBConn($this->db_type);
		$this->logger = new TinLogger(LOGIC_LOG_PATH, "TinBaseLogic");
	}
	public function __destruct(){ 
        
    }
    /** 获取当前链接对象 */
	protected function getConn() {
		return $this->dbConn;
	}
//	protected function beginTrans() {
//		$this->dbConn->Execute('begin');
//	}
//
//	protected function endTrans() {
//		$this->dbConn->Execute('commit');
//	}
//	protected function rollback() {
//		$this->dbConn->Execute('rollback');
//	}
    /** 开启数据库事务 */
	protected function beginTrans() {
		if($this->dbConn->hasTransactions){
			$this->dbConn->SetTransactionMode('SERIALIZABLE');
			$this->dbConn->StartTrans();
		}
	}
    /** 关闭并提交数据库事务 */
	protected function endTrans() {
		if($this->dbConn->hasTransactions){
			$returnVal = $this->dbConn->CompleteTrans();
			$this->dbConn->SetTransactionMode('');
			return $returnVal;
		}
	}
    /** 事务失败回滚 */
	protected function giveUpTrans() {
		$this->dbConn->FailTrans();
	}
    /** 检测当前的TinDataMap是否异常 */
	protected function checkTypes(& $tinData) {
		return $tinData->checkTypeValid();
	}
    
}
?>
